function filterFormWithEmptyValue(params) {
  const newParams = JSON.parse(JSON.stringify(params));
  Object.keys(params).forEach((key) => {
    if (!params[key]) delete newParams[key];
  });
  return newParams;
}

function filterQuestionwithEmptyValue(params) {
  const newParams = JSON.parse(JSON.stringify(params));
  Object.keys(params).forEach((key) => {
    if (!params[key] || params[key] === '全部') delete newParams[key];
  });
  return newParams;
}

const types = ["单选题", "多选题", "简答题", "编程题"];

function sortformTypes(questions) {
  return questions.sort(
    (a, b) => types.indexOf(a.type) - types.indexOf(b.type)
  );
}

module.exports = {
  filterFormWithEmptyValue,
  filterQuestionwithEmptyValue,
  sortformTypes
};
